* Summary statistics before standardization

use "$project_path/data/4_regdata/regdata.dta", clear

sum diff_m1_growth_gdp_penn
sum diff_m1_inflation_imf
sum diff_m1_unemployment_ilo
sum diff_m1_trade_wb
sum diff_m1_hdi
sum diff_m1_democracy_index

* Export table
//Initialize matrix to store stats
local ncols = 4
local nrows = 6

mat Stats = J(`nrows', `ncols', .)


local varlist diff_m1_growth_gdp_penn ///
				diff_m1_inflation_imf ///
				diff_m1_unemployment_ilo ///
				diff_m1_trade_wb ///
				diff_m1_hdi ///
				diff_m1_democracy_index

local row = 0
foreach var in `varlist'{
	
	local ++row
	
	sum `var'
	local mean_`var': di %5.3f r(mean)
	local sd_`var': di %5.3f r(sd)
	local min_`var': di %5.3f r(min)
	local max_`var': di %5.3f r(max)
	
	mat Stats[`row', 1]=`mean_`var''	
	mat Stats[`row', 2]=`sd_`var''
	mat Stats[`row', 3]=`min_`var''
	mat Stats[`row', 4]=`max_`var''

}	

clear 
svmat Stats

forval i = 1/4{
	
	tostring Stats`i', replace force format(%04.3f)
}

rename Stats1 mean
rename Stats2 sd
rename Stats3 min
rename Stats4 max

//Edit table
gen outcome = ""
gen unit = ""

local outcome `" "GDP per capita growth" "Inflation (CPI)" "Unemployment" "Trade intensity" "HDI" "Democracy index" "'
local unit `" "\%" "\%" "\% of labor force" "\% of GDP" "0–1 scale" "0–1 scale" "'

local row = 1
foreach oc in `outcome' {
	
	replace outcome = "`oc'" in `row'
	local ++row
}

local row = 1
foreach ut in `unit' {
	
	replace unit = "`ut'" in `row'
	local ++row
}

order outcome mean sd min max unit 

label var outcome "Outcome"
label var mean "Mean"
label var sd "s.d."
label var min "min."
label var max "max."
label var unit "Unit"

//Add options
local output "$project_path/output/appendix_tables/Appendix_Table_B3.tex"
local title = "Measures of country performance: Summary statistics"
local marker = "tab:des_stat_components"
local footnote = "\caption*{\footnotesize \textit{Notes}: This table lists the main variables which we use to measure country performance, defined for each outcome as the difference between the average level of that outcome in the four years following the election and its level in the year before the election.}"

texsave using "`output'", replace title("`title'") varlabels footnote("`footnote'") frag marker("`marker'") nofix location(H)



